var FlashPrintFix = {};
FlashPrintFix.createStyle = function (cssCode) {
	var styleElement = document.createElement("style");

	styleElement.type = "text/css";
	if (styleElement.styleSheet) {
		styleElement.styleSheet.cssText = cssCode;
	} else {
		styleElement.appendChild(document.createTextNode(cssCode));
	}

	document.getElementsByTagName("head")[0].appendChild(styleElement);
};

FlashPrintFix.needPrintFix = function () {
	return /firefox|opera/i.test(navigator.userAgent);
};

if (FlashPrintFix.needPrintFix()) {
	FlashPrintFix.createStyle(
		"@media screen\n" +
		".flashScreenshot { display: none; }\n" +
		"@media print\n" +
		".printableFlashObj { display: none; };\n" +
		".flashScreenshot { display: block; border: 0; outline: none; }"
	);
}

FlashPrintFix.setImg = function(objId, imgData) {
	var obj = document.getElementById(objId);
	if (obj === null) {
		throw new Error("Can't find node with id '" + objId + "'");
	}
	
	obj.setAttribute("class", "printableFlashObj");
	
	var container = obj.parentNode;
	if (container.nodeName === "OBJECT") {
		container = container.parentNode;
	}
	
	var img = document.createElement("img");
	img.setAttribute("class", "flashScreenshot");
	img.src = "data:image/png;base64,"+imgData;
	
	container.appendChild(img);
};
